//
//  CellForHot.m
//  MY Project For Sport
//
//  Created by dllo on 16/1/22.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForHot.h"
#import "ModelForHot.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <DKNightVersion.h>
#import "UIColor+Wonderful.h"
#define WEIGHT self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CellForHot ()

@property (nonatomic, retain) UILabel *team1;
@property (nonatomic, retain) UILabel *team2;
@property (nonatomic, retain) UILabel *score1;
@property (nonatomic, retain) UILabel *score2;
@property (nonatomic, retain) UILabel *leagueType;
@property (nonatomic, retain) UILabel *round;
@property (nonatomic, retain) UIImageView *team1View;
@property (nonatomic, retain) UIImageView *team2View;
@property (nonatomic ,retain) UIView *myView;
@property (nonatomic, retain) UILabel *current;
@property (nonatomic, retain) UILabel *data;
@property (nonatomic, retain) UILabel *extra1;
@property (nonatomic, retain) UILabel *extra2;
@property (nonatomic, retain) UILabel *extra3;

@end


@implementation CellForHot

- (void)dealloc {
    [_team1 release];
    [_team2 release];
    [_score1 release];
    [_score2 release];
    [_leagueType release];
    [_round release];
    [_team1View release];
    [_team2View release];
    [_myView release];
    [_current release];
    [_extra1 release];
    [_extra2 release];
    [_extra3 release];
    [_data release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithColors([UIColor linenColor], [UIColor grayColor]);
        
        [self createSubview];
        
    }
    
    return self;

}

#pragma mark - 创建 cell 上面的子视图
- (void)createSubview {
    
    
    self.myView = [[UIView alloc] init];
    [self.contentView addSubview:self.myView];
    [_myView release];
    self.myView.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor dimGray]);
    
    self.leagueType = [[UILabel alloc] init];
    [self.contentView addSubview:self.leagueType];
    [_leagueType release];
    self.leagueType.font = [UIFont systemFontOfSize:12];
    self.leagueType.adjustsFontSizeToFitWidth = YES;
    
    self.round = [[UILabel alloc] init];
    [self.contentView addSubview:self.round];
    [_round release];
    self.round.font = [UIFont systemFontOfSize:12];
    self.round.adjustsFontSizeToFitWidth = YES;
    
    self.team1 = [[UILabel alloc] init];
    [self.contentView addSubview:self.team1];
    [_team1 release];
    
    
    self.team2 = [[UILabel alloc] init];
    [self.contentView addSubview:self.team2];
    [_team2 release];
    
    self.score1 = [[UILabel alloc] init];
    [self.contentView addSubview:self.score1];
    [_score1 release];
    self.score1.font = [UIFont systemFontOfSize:19];
    
    
    self.score2 = [[UILabel alloc] init];
    [self.contentView addSubview:self.score2];
    [_score2 release];
    self.score2.font = [UIFont systemFontOfSize:19];
    
    self.team1View = [[UIImageView alloc] init];
    [self.contentView addSubview:self.team1View];
    [_team1View release];
    
    self.team2View = [[UIImageView alloc] init];
    [self.contentView addSubview:self.team2View];
    [_team2View release];
    
    self.current = [[UILabel alloc] init];
    [self.contentView addSubview:self.current];
    [_current release];
    
    
    self.extra1 = [[UILabel alloc] init];
    [self.contentView addSubview:self.extra1];
    [_extra1 release];
    
    self.extra2 = [[UILabel alloc] init];
    [self.contentView addSubview:self.extra2];
    [_extra2 release];
    
    self.extra3 = [[ UILabel alloc] init];
    [self.contentView addSubview:self.extra3];
    [_extra3 release];

    self.data = [[UILabel alloc] init];
    [self.contentView addSubview:self.data];
    [_data release];
    
}

-(void)layoutSubviews {
    
    
    [super layoutSubviews];
     //NSLog(@"%f %f", self.contentView.frame.size.width, HEIGHT);

    self.myView.frame = CGRectMake(3 * WEIGHTT, 5 * HEIGHTT, WEIGHT - 6 * WEIGHTT, HEIGHT - 10 * HEIGHTT);
    
    //  NSLog(@"%f", self.contentView.frame.size.height);
    self.leagueType.frame = CGRectMake(10 * WEIGHTT, 10 * HEIGHTT, WEIGHT / 8, HEIGHT / 8.4);
    self.leagueType.dk_textColorPicker = DKColorWithColors([UIColor grayColor], [UIColor whiteColor]);
    
    self.round.frame = CGRectMake(WEIGHT / 8 + (10 + 5) * WEIGHTT, 10 * HEIGHTT, WEIGHT / 8, HEIGHT / 8.4);
  //  self.round.textColor = [UIColor grayColor];
    self.data.frame = CGRectMake(WEIGHT / 3 * 2, 10 * HEIGHTT, WEIGHT / 4, HEIGHT / 8.4);
  //  self.data.adjustsFontSizeToFitWidth = YES;
   // self.data.backgroundColor = [UIColor redColor];
    
    
    self.round.dk_textColorPicker = DKColorWithColors([UIColor grayColor], [UIColor whiteColor]);
    
    self.team1View.frame = CGRectMake(10 * WEIGHTT, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT, WEIGHT / 8.3, WEIGHT / 8.3);
    self.team1View.layer.cornerRadius = WEIGHT / 16.6;
    self.team1View.layer.masksToBounds = YES;
    
    self.team2View.frame = CGRectMake(10 * WEIGHTT, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT, WEIGHT / 8.3 ,WEIGHT / 8.3);
    self.team2View.layer.cornerRadius = WEIGHT / 16.6;
    self.team2View.layer.masksToBounds = YES;

    
    self.team1.frame = CGRectMake(10 * WEIGHTT +  HEIGHT / 5 + 10 * WEIGHTT, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT, WEIGHT / 3.1, WEIGHT / 8.3);
    self.team1.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
   // self.team1.backgroundColor = [UIColor redColor];
    
    self.team2.frame = CGRectMake(10 * WEIGHTT +  HEIGHT / 5 + 10 * WEIGHTT, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT, WEIGHT / 3.1,WEIGHT / 8.3);
    self.team2.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);

    
    self.score1.frame = CGRectMake(WEIGHT / 1.8, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT, WEIGHT / 10, WEIGHT / 8.3);
    self.score1.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    //self.score1.backgroundColor = [UIColor yellowColor];
    
    
    self.score2.frame = CGRectMake(WEIGHT / 1.8, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT, WEIGHT / 10, WEIGHT / 8.3);
    self.score2.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);

    self.current.frame = CGRectMake(WEIGHT / 1.5 + WEIGHT / 10 + 20 * WEIGHTT,(10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT) / 2, WEIGHT / 8, WEIGHT / 8);
    self.current.backgroundColor = Wonderful_GrayColor2;

    self.current.layer.cornerRadius = WEIGHT / 16;
    self.current.layer.masksToBounds = YES;
    self.current.text = @"结束";
    self.current.textAlignment = NSTextAlignmentCenter;
    
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(10 * WEIGHTT , 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT, WEIGHT / 20, WEIGHT / 17)];
   // view.backgroundColor = [UIColor redColor];
    view.image = [UIImage imageNamed:@"iconfont-shipin"];
    [self.contentView addSubview:view];
    [view release];
    
    self.extra1.frame = CGRectMake(10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT, WEIGHT - 8 * WEIGHTT - (10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8), WEIGHT /17);
   // self.extra1.backgroundColor = [UIColor grayColor];
    
    
    UIImageView *view2 = [[UIImageView alloc] initWithFrame:CGRectMake(10 * WEIGHTT , 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT, WEIGHT / 20, WEIGHT / 17)];
    // view.backgroundColor = [UIColor redColor];
    view2.image = [UIImage imageNamed:@"iconfont-wenben-copy"];
    [self.contentView addSubview:view2];
    [view2 release];

    
    self.extra2.frame = CGRectMake(10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT, WEIGHT - 8 * WEIGHTT - (10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8), WEIGHT /17);
    //self.extra2.backgroundColor = [UIColor grayColor];
    
    
    UIImageView *view3 = [[UIImageView alloc] initWithFrame:CGRectMake(10 * WEIGHTT , 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT, WEIGHT / 20, WEIGHT / 17)];
    // view.backgroundColor = [UIColor redColor];
    view3.image = [UIImage imageNamed:@"iconfont-wenben-copy"];
    [self.contentView addSubview:view3];
    [view3 release];

    
    self.extra3.frame = CGRectMake(10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8, 10 * HEIGHTT + HEIGHT / 8.4 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + HEIGHT / 5 + 10 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT + WEIGHT / 17 + 8 * HEIGHTT,WEIGHT - 8 * WEIGHTT - (10 * WEIGHTT + WEIGHT / 20 + WEIGHTT * 8), WEIGHT /17);
  //  self.extra3.backgroundColor = [UIColor grayColor];
    
    self.extra1.textColor = [UIColor grayColor];
    self.extra2.textColor = [UIColor grayColor];
    self.extra3.textColor = [UIColor grayColor];
    

}

-(void)passModelForHot:(ModelForHot *)hotModel {
    
    self.leagueType.text = hotModel.LeagueType_cn;
    self.round.text = hotModel.Round_cn;
    //    self.date.text = hotModel.date;
    self.team1.text = hotModel.Team1;
    self.team2.text = hotModel.Team2;
    self.score1.text = hotModel.Score1;
    self.score2.text = hotModel.Score2;
    
    self.extra1.text = [hotModel.extra[0] objectForKey:@"title"];
    self.extra2.text = [hotModel.extra[1] objectForKey:@"title"];
    self.extra3.text = [hotModel.extra[2] objectForKey:@"title"];
    
    self.data.font = [UIFont systemFontOfSize:15];
    self.data.text = hotModel.date;
    [self.team1View sd_setImageWithURL:[NSURL URLWithString:hotModel.Flag1]];
    
    [self.team2View sd_setImageWithURL:[NSURL URLWithString:hotModel.Flag2]];
 
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
